<template>
  <div>
    关键字:
    <el-input
      clearable
      v-model="data.params.projectName"
      placeholder="项目名称/编号"
      @keyup.enter="search"
      style="width: 200px; margin-right: 15px"
    />
    <el-button class="ordinary" @click="search()">搜索</el-button>
    <Table
      :height="350"
      :hasOperate="true"
      :loading="data.isLoading"
      :table-arr="data.allTableData"
      :columns="data.columns"
      @selectList="getCurrentList"
      @rowClick="getCurrentRow"
    >
    </Table>
    <div class="example-pagination-block">
      <el-pagination
        background
        layout="prev, pager, next ,total,sizes,jumper"
        :total="data.total"
        :page-size="data.params.size"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import Table from '@/views/project/components/table-dialog/table.vue'
import tableData from './tableProject.json'
import { getProjectList } from '../../../api/project'

export default defineComponent({
  components: {
    Table,
  },
  emits: {
    getProject: null,
  },
  setup(props, { emit }) {
    const examineForm = ref()
    let data = reactive({
      params: {
        current: 1,
        size: 10,
        projectName: '',
        level: '',
        createOrgId: '',
        projectCategory: '',
        projectStatus:'0'
      },
      isLoading: false,
      allTableData: [],
      total: 0,
      columns: tableData.platformTableHeader,
      currentList: [],
      ids: [],
    })
    const form = reactive({
      reportTime: '',
      releaseContent: '',
      fileName: '',
      filePath: '',
    })
    const onSearch = async () => {
      data.isLoading = true
      getProjectList(data.params).then((res) => {
        data.isLoading = false
        let records = res.data.data.records
        records.map((item) => {
          if (item.projectStatus == 0) {
            item.projectStatus = '启用'
          } else {
            item.projectStatus = '停用'
          }
        })
        data.allTableData = records
        data.total = res.data.data.total
      })
    }
    const search = () => {
      data.params.current = 1
      console.log(data.params)
      onSearch()
    }
    const hasChoose = () => {
      return data.currentList
    }
    const getCurrentList = (currentList) => {
      console.log(currentList, 'getCurrentList')
      data.currentList = currentList
      data.ids = currentList.map((item) => {
        return item.id
      })
    }
    const getCurrentRow = (row) => {
      emit('getProject', row)
    }
    onSearch()
    //改变页码
    const handleCurrentChange = (e) => {
      console.log(e, 'handleCurrentChange')
      data.params.current = e
      onSearch()
    }
    //改变页数限制
    const handleSizeChange = (e) => {
      console.log(e, 'handleSizeChange')
      data.params.size = e
      onSearch()
    }
    return {
      data,
      process,
      form,
      examineForm,
      search,
      onSearch,
      hasChoose,
      getCurrentList,
      getCurrentRow,
      handleCurrentChange,
      handleSizeChange,
    }
  },
})
</script>

<style scoped></style>
